package com.huike.pmps.controller;

import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Member;
import com.huike.pmps.model.entity.SupplierWarehouseReceipt;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.SupplierWarehouseReceiptService;
import com.huike.pmps.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@RestController
@RequestMapping("/api/supplier_warehouse_receipts")
@Api(tags = "PO课程-供应商-入库管理")
@Slf4j
public class SupplierWarehouseReceiptController {
    @Autowired
    SupplierWarehouseReceiptService supplierWarehouseReceiptService;

    @ApiOperation(value = "入库，生成入库单", httpMethod = "POST")
    @PostMapping
    public Result insertSupplierWarehouseReceipt(SupplierWarehouseReceipt supplierWarehouseReceipt) {
        return supplierWarehouseReceiptService.insertSupplierWarehouseReceipt(supplierWarehouseReceipt);
    }

    @ApiOperation(value = "根据主键ID删除入库单", httpMethod = "DELETE")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return supplierWarehouseReceiptService.deleteById(id);
    }

    @ApiOperation(value = "入库课程总览", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "客户名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "supplierName", value = "供应商名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "courseChargeName", value = "课程编导", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "courseName", value = "课程名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "courseQualityEvaluation", value = "课程质量评价", paramType = "query", dataType = "int"),
    })
    @GetMapping
    public Result selectByCondition(HttpServletRequest request, PageInfo pageInfo, String customerName, String supplierName, String courseChargeName,String courseName,Integer courseQualityEvaluation) {
        //从请求头中获取token
        Member member = (Member) request.getSession().getAttribute(TokenUtil.getToken(request));
        return supplierWarehouseReceiptService.selectByCondition(member, pageInfo, customerName, supplierName, courseChargeName,courseName,courseQualityEvaluation);
    }

    @ApiOperation(value = "获取入库单详情", httpMethod = "GET")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable("id") Integer id) {
        return supplierWarehouseReceiptService.selectById(id);
    }

}
